package com.teach.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.teach.dto.CommentsSearch;
import com.teach.entity.Comments;

public interface CommentsMapper {
    int deleteByPrimaryKey(Long commentId);

    int insert(Comments record);

    int insertSelective(Comments record);

    Comments selectByPrimaryKey(Long commentId);

    int updateByPrimaryKeySelective(Comments record);

    int updateByPrimaryKey(Comments record);
    /**
     * 统计被评论者的数量
     * @param commentCommentator 被评论者的主键
     * @return 被评论者的数量
     */
    @Select("select count(*) from comments where comment_commentator=#{commentCommentator} and comment_delete=0")
    Long count(
    		@Param("commentCommentator") Long commentCommentator
    );
    
    /**
     * 查询被评论者的所有评论
     * @param commentCommentator 被评论者的主键
     * @return 被评论者的所有评论
     */
    List<Comments> selectByCommmetCommentator(
    		@Param("commentCommentator") Long commentCommentator
    );
    
    @Select("select * from comments WHERE comment_commentator=#{commentCommentator} and comment_delete=0 order by comment_time desc LIMIT 10 ")
    List<Comments> selectByCommmetCommentator1(
    		@Param("commentCommentator") Long commentCommentator
    );
    
    /**
     * 修改所有被评论者评论的状态
     * @param commentCommentator 被评论者的主键
     * @return
     */
    @Update("update comments set comment_delete=1 where comment_commentator=#{commentCommentator}")
    int updateByCommentCommentator(
    		@Param("commentCommentator") Long commentCommentator
    );
    
    /**
     * 修改单条评论的状态
     * @param commentUserName 评论的用户名
     * @param commentCommentator 被评论者的主键
     * @return
     */
    @Update("update comments set comment_delete=1 where comment_user_name=#{commentUserName} and comment_commentator=#{commentCommentator}")
    int updateByCommentUserName(
    		@Param("commentUserName") String commentUserName,
    		@Param("commentCommentator") Long commentCommentator
    );
    /**
     * 带搜索条件的查询（不含理论上删除了的）
     * @param search 搜索条件
     * @return 查询的结果集
     */
    List<Comments> select(CommentsSearch search);
    
    /**
     * 带搜索条件的查询（包含理论上删除了的）
     * @param search 搜索条件
     * @return 查询的结果集
     */
    List<Comments> selectAll(CommentsSearch search);
    
    @Select("select * from comments where comment_user_name=#{commentUserName} and comment_commentator=#{commentCommentator} and comment_delete=0")
    List<Comments> selectByUserName(
    		@Param("commentUserName") String commentUserName,
    		@Param("commentCommentator") Long commentCommentator
    );
}